/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.net.entitybean;

import java.io.Serializable;
import java.sql.Date;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import oracle.jdbc.OracleTypes;
import queenb.net.annotation.Mapping;
import queenb.net.datacontrol.DataControl;
import queenb.web.importExcel.controller.importController;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class N500 extends DataControl<N500> implements Serializable {

    @Mapping(name = "PN100", typeMapping = OracleTypes.INTEGER)
    private int fn100;
    @Mapping(name = "PN500", typeMapping = OracleTypes.INTEGER)
    private int fn500;
    @Mapping(name = "nd501", typeMapping = OracleTypes.DATE)
    private Date nd501;
    @Mapping(name = "pn000", typeMapping = OracleTypes.INTEGER)
    private int fn000;
    @Mapping(name = "fc250", typeMapping = OracleTypes.INTEGER)
    private String fc250;
    @Mapping(name = "nv502", typeMapping = OracleTypes.CHAR)
    private String nv502;
    @Mapping(name = "nv503", typeMapping = OracleTypes.CHAR)
    private String nv503;
    @Mapping(name = "nv504", typeMapping = OracleTypes.CHAR)
    private String nv504;
    @Mapping(name = "nd505", typeMapping = OracleTypes.DATE)
    private Date nd505;
    @Mapping(name = "hoten", typeMapping = OracleTypes.CHAR)
    private String hoten;
    @Mapping(name = "nv116", typeMapping = OracleTypes.CHAR)
    private String msnv;
    @Mapping(name = "nv451", typeMapping = OracleTypes.CHAR)
    private String bophan;
    @Mapping(name = "fn450", typeMapping = OracleTypes.INTEGER)
    private int fn450;
    @Mapping(name = "fn850", typeMapping = OracleTypes.INTEGER)
    private int fn850;
    @Mapping(name = "NN509", typeMapping = OracleTypes.INTEGER)
    private int nn509;
    @Mapping(name = "NN510", typeMapping = OracleTypes.INTEGER)
    private int nn510;
    @Mapping(name = "NN511", typeMapping = OracleTypes.INTEGER)
    private int nn511;
    @Mapping(name = "NN512", typeMapping = OracleTypes.INTEGER)
    private int nn512;
     @Mapping(name = "NN513", typeMapping = OracleTypes.INTEGER)
    private int nn513;
    @Mapping(name = "nv851", typeMapping = OracleTypes.CHAR)
    private String nhomto;
    @Mapping(name = "nv506", typeMapping = OracleTypes.CHAR)
    private String nv506;
    @Mapping(name = "nv507", typeMapping = OracleTypes.CHAR)
    private String nd507;
     @Mapping(name = "nl519", typeMapping = OracleTypes.CHAR)
    private String nl519;
    @Mapping(name = "nd508", typeMapping = OracleTypes.CHAR)
    private String nd508;
    private Date from;
    private Date to;
    private long daylater;// so ngay nghi con lai
    @Mapping(name = "NV001", typeMapping = OracleTypes.CHAR)
    private String nv001;
    private String colorEvent;
    private boolean flag;
    @Mapping(name = "nd501", typeMapping = OracleTypes.CHAR)
    private String nd501str;
    @Mapping(name = "nd505", typeMapping = OracleTypes.CHAR)
    private String nd505str;
    private boolean allDay;
    @Mapping(name = "PN500", typeMapping = OracleTypes.INTEGER)
    private int pn500;
    /**
     * @return the fn000
     */
    public int getFn000() {
        return fn000;
    }

    /**
     * @param fn000 the fn000 to set
     */
    public void setFn000(int fn000) {
        this.fn000 = fn000;
    }

    /**
     * @return the fc250
     */
    public String getFc250() {
        return fc250;
    }

    /**
     * @param fc250 the fc250 to set
     */
    public void setFc250(String fc250) {
        this.fc250 = fc250;
    }

    /**
     * @return the nv502
     */
    public String getNv502() {
        return nv502;
    }

    /**
     * @param nv502 the nv502 to set
     */
    public void setNv502(String nv502) {
        this.nv502 = nv502;
    }

    /**
     * @return the nv503
     */
    public String getNv503() {

        return nv503;
    }

    /**
     * @param nv503 the nv503 to set
     */
    public void setNv503(String nv503) {
        this.nv503 = nv503;
    }

    /**
     * @return the nv504
     */
    public String getNv504() {
        return nv504;
    }

    /**
     * @param nv504 the nv504 to set
     */
    public void setNv504(String nv504) {
        this.nv504 = nv504;
    }

    /**
     * @return the hoten
     */
    public String getHoten() {
        return hoten;
    }

    /**
     * @param hoten the hoten to set
     */
    public void setHoten(String hoten) {
        this.hoten = hoten;
    }

    /**
     * @return the msnv
     */
    public String getMsnv() {
        return msnv;
    }

    /**
     * @param msnv the msnv to set
     */
    public void setMsnv(String msnv) {
        this.msnv = msnv;
    }

    /**
     * @return the bophan
     */
    public String getBophan() {
        return bophan;
    }

    /**
     * @param bophan the bophan to set
     */
    public void setBophan(String bophan) {
        this.bophan = bophan;
    }

    /**
     * @return the nhomto
     */
    public String getNhomto() {
        return nhomto;
    }

    /**
     * @param nhomto the nhomto to set
     */
    public void setNhomto(String nhomto) {
        this.nhomto = nhomto;
    }

    /**
     * @return the nd501
     */
    public Date getNd501() {

        return nd501;
    }

    /**
     * @param nd501 the nd501 to set
     */
    public void setNd501(Date nd501) {

        this.nd501 = nd501;
    }

    /**
     * @return the nd505
     */
    public Date getNd505() {
        return nd505;
    }

    /**
     * @param nd505 the nd505 to set
     */
    public void setNd505(Date nd505) {
        this.nd505 = nd505;
    }

    /**
     * @return the from
     */
    public Date getFrom() {
        Calendar c = Calendar.getInstance();
        try {
            int day = nd501.getDate() + 1;

            c.setTime(nd501);
            c.add(Calendar.DATE, 1);
            from = Util.toSQLDate(c.getTime());

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }


        return from;
    }

    /**
     * @param from the from to set
     */
    public void setFrom(Date from) {
        this.from = from;
    }

    /**
     * @return the to
     */
    public Date getTo() {
        Calendar c = Calendar.getInstance();
        try {
            int day = nd505.getDate() + 1;

            c.setTime(nd505);
            c.add(Calendar.DATE, 1);
            to = Util.toSQLDate(c.getTime());

        } catch (Exception e) {
            System.out.println("=====" + e.getMessage());
        }
        return to;
    }

    /**
     * @param to the to to set
     */
    public void setTo(Date to) {
        this.to = to;
    }

    /**
     * @return the fn100
     */
    public int getFn100() {
        return fn100;
    }

    /**
     * @param fn100 the fn100 to set
     */
    public void setFn100(int fn100) {
        this.fn100 = fn100;
    }

    /**
     * @return the fn450
     */
    public int getFn450() {
        return fn450;
    }

    /**
     * @param fn450 the fn450 to set
     */
    public void setFn450(int fn450) {
        this.fn450 = fn450;
    }

    /**
     * @return the fn850
     */
    public int getFn850() {
        return fn850;
    }

    /**
     * @param fn850 the fn850 to set
     */
    public void setFn850(int fn850) {
        this.fn850 = fn850;
    }

    /**
     * @return the nv001
     */
    public String getNv001() {
        return nv001;
    }

    /**
     * @param nv001 the nv001 to set
     */
    public void setNv001(String nv001) {
        this.nv001 = nv001;
    }

    

    /**
     * #877B30
     * @return the colorEvent
     */
    public String getColorEvent() {
        if (nv503 != null) {
            if (nv503.equals("A") && fn000 !=8) {
                colorEvent = "#095A99";
            }
            if(nv503.equals("A") && fn000 ==8) {
                colorEvent = "#877B30";
            }
            if (nv503.equals("B") && fn000 !=8){
                 colorEvent = "#378006";
            }
            if (nv503.equals("B") && fn000 ==8){
                 colorEvent = "#877B30";
            }
        }
        return colorEvent;
    }

    /**
     * @param colorEvent the colorEvent to set
     */
    public void setColorEvent(String colorEvent) {
        this.colorEvent = colorEvent;
    }

    /**
     * @return the daylater
     */
    public long getDaylater() throws ParseException {
        if (nd501 != null && nd505 != null) {
            Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nd501Str = formatter.format(nd501);
            Format formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nd505Str = formatter1.format(nd505);


            String day = nd501Str.substring(8, 10);
            String mont = nd501Str.substring(5, 7);
            String yyy = nd501Str.substring(0, 4);
            String datetotal = mont + "-" + day + "-" + yyy;
            String day1 = nd505Str.substring(8, 10);
            String mont1 = nd505Str.substring(5, 7);
            String yyy1 = nd505Str.substring(0, 4);
            String datetotal1 = mont1 + "-" + day1 + "-" + yyy1;

//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        	java.util.Date date1 = sdf.parse(datetotal1);
//        	java.util.Date date2 = sdf.parse(datetotal);
//                
//                 System.out.println("------------BBBBBBBBBBBBB----" +   date1.compareTo(date2));

            daylater = dayiff(parseDate(datetotal1), parseDate(datetotal));               //daydiff(parseDate(datetotal), parseDate(datetotal1)); 
            return daylater;
            //  $j(this).parent().parent().parent().next().children().children().next().children().next().val(dayssss);
        } else {
            return 0;
        }

    }

    public long dayiff(java.sql.Date first, java.sql.Date second) {
        try {
            return (second.getTime() - first.getTime()) / (1000 * 60 * 60 * 24);
        } catch (Exception e) {
            return 0;
        }
    }

    public Date parseDate(String dayss) {
        try {
            String[] mdy = dayss.split("/");
            int id = Integer.parseInt(mdy[0]);
            int id1 = Integer.parseInt(mdy[1]);
            int id2 = Integer.parseInt(mdy[2]);
            return new Date(id2, id - 1, id1);
        } catch (Exception e) {
            return nd501;
        }
    }

    /**
     * @param daylater the daylater to set
     */
    public void setDaylater(long daylater) {
        this.daylater = daylater;
    }

    /**
     * @return the nd506
     */
    public String getNv506() {
        return nv506;
    }

    /**
     * @param nd506 the nd506 to set
     */
    public void setNv506(String nv506) {
        this.nv506 = nv506;
    }

    /**
     * @return the nd507
     */
    public String getNd507() {
        return nd507;
    }

    /**
     * @param nd507 the nd507 to set
     */
    public void setNd507(String nd507) {
        this.nd507 = nd507;
    }

    /**
     * @return the nd508
     */
    public String getNd508() {
        return nd508;
    }

    /**
     * @param nd508 the nd508 to set
     */
    public void setNd508(String nd508) {
        this.nd508 = nd508;
    }

    /**
     * @return the flag
     */
    public boolean isFlag() {
        if (nv506 != null) {


            if (nv506.length() > 0) {
                setFlag(true);
            } else {
                setFlag(false);
            }
        }else{
           setFlag(false);  
        }
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    /**
     * @return the nl519
     */
    public String getNl519() {
        return nl519;
    }

    /**
     * @param nl519 the nl519 to set
     */
    public void setNl519(String nl519) {
        this.nl519 = nl519;
    }

    /**
     * @return the start
     */
    public static String convertDateToString(Date date, String format) {
    SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat(format);
    return mySimpleDateFormat.format(date);
}
//    public String getStart() {
////        Calendar c = Calendar.getInstance();
////        try {
////            int day = nd501.getDate();
////
////            c.setTime(nd501);
////            c.add(Calendar.DATE, 0);
////            from = Util.toSQLDate(c.getTime());
////
////        } catch (Exception e) {
////            System.out.println(e.getMessage());
////        }
////        String adbc = "T"+"8"+":"+"0";
////        start = convertDateToString(from,"yyyy-MM-dd");
////        String total = start+adbc;
//        System.out.println("------------------STRING-------"+start);
//        return "2013-05-17T08:30:00";
//    }
//
//    /**
//     * @param start the start to set
//     */
//    public void setStart(String start) {
//        this.start = start;
//    }
//
//    /**
//     * @return the end
//     */
//    public String getEnd() {
////      Calendar c = Calendar.getInstance();
////        try {
////            int day = nd501.getDate();
////
////            c.setTime(nd501);
////            c.add(Calendar.DATE, 0);
////            from = Util.toSQLDate(c.getTime());
////
////        } catch (Exception e) {
////            System.out.println(e.getMessage());
////        }
////         String adbc = "T"+"12"+":"+"0";
////        end = convertDateToString(from,"yyyy-MM-dd");
////        String total = end+adbc;
//        System.out.println("------------------STRING--AAAAAAAAAA-----"+end);
//        return "2013-05-17T14:30:00";
//        
//    }
//
//    /**
//     * @param end the end to set
//     */
//    public void setEnd(String end) {
//        this.end = end;
//    }

    /**
     * @return the allDay
     */
    public boolean isAllDay() {
//        if(nn510!=0 && nn512!=0){
//            System.out.println("--------------ALLDAY--------"+allDay);
//            setAllDay(false);
//        }else{
//            setAllDay(true);
//        }
//        
//         System.out.println("---------1111111111111-----ALLDAY--------"+allDay);
        return allDay;
    }

    /**
     * @param allDay the allDay to set
     */
    public void setAllDay(boolean allDay) {
        this.allDay = allDay;
    }

    /**
     * @return the nd501str
     */
    public String getNd501str() {
        nd501str = nd501str.substring(0, 10);
        
       
        String total=null;
        if(nn510 < 10 && nn511<10){
              total = "T"+"0"+nn510+":"+"0"+nn511;
        }else if(nn510 < 10 && nn511 > 10){
            total = "T"+"0"+nn510+":"+nn511;
        }else if(nn510 > 10 && nn511 < 10){
            total = "T"+nn510+":"+"0"+nn511;
        }else if(nn510 > 10 && nn511 > 10){
            total = "T"+nn510+":"+nn511;
        }else if(nn510 == 10 && nn511 > 10){
            total = "T"+nn510+":"+nn511;
        }else if(nn510 > 10 && nn511 == 10){
            total = "T"+nn510+":"+nn511;
        }else if(nn510 == 10 && nn511 == 10){
            total = "T"+nn510+":"+nn511;
        }else if(nn510 == 10 && nn511 < 10){
            total = "T"+nn510+":"+"0"+nn511;
        }else if(nn510 < 10 && nn511 == 10){
            total = "T"+"0"+nn510+":"+nn511;
        }

        return nd501str+total;
       
    }

    /**
     * @param nd501str the nd501str to set
     */
    public void setNd501str(String nd501str) {
        this.nd501str = nd501str;
    }

    /**
     * @return the nd505str
     */
    public String getNd505str() {
          nd505str = nd505str.substring(0, 10);
         
         String total=null;
        if(nn512 < 10 && nn513<10){
              total = "T"+"0"+nn512+":"+"0"+nn513;
        }else if(nn512 < 10 && nn513 > 10){
            total = "T"+"0"+nn512+":"+nn513;
        }else if(nn512 > 10 && nn513 < 10){
            total = "T"+nn512+":"+"0"+nn513;
        }else if(nn512 > 10 && nn513 > 10){
            total = "T"+nn512+":"+nn513;
        }else if(nn512 == 10 && nn513 > 10){
            total = "T"+nn512+":"+nn513;
        }else if(nn512 > 10 && nn513 == 10){
            total = "T"+nn512+":"+nn513;
        }else if(nn512 == 10 && nn513 == 10){
            total = "T"+nn512+":"+nn513;
        }else if(nn512 == 10 && nn513 < 10){
            total = "T"+nn512+":"+"0"+nn513;
        }else if(nn512 < 10 && nn513 == 10){
            total = "T"+"0"+nn512+":"+nn513;
        }

        return nd505str+total;
       
    }

    /**
     * @param nd505str the nd505str to set
     */
    public void setNd505str(String nd505str) {
        this.nd505str = nd505str;
    }

    /**
     * @return the nn509
     */
    public int getNn509() {
        return nn509;
    }

    /**
     * @param nn509 the nn509 to set
     */
    public void setNn509(int nn509) {
        this.nn509 = nn509;
    }

    /**
     * @return the nn510
     */
    public int getNn510() {
        return nn510;
    }

    /**
     * @param nn510 the nn510 to set
     */
    public void setNn510(int nn510) {
        this.nn510 = nn510;
    }

    /**
     * @return the nn511
     */
    public int getNn511() {
        return nn511;
    }

    /**
     * @param nn511 the nn511 to set
     */
    public void setNn511(int nn511) {
        this.nn511 = nn511;
    }

    /**
     * @return the nn512
     */
    public int getNn512() {
        return nn512;
    }

    /**
     * @param nn512 the nn512 to set
     */
    public void setNn512(int nn512) {
        this.nn512 = nn512;
    }

    /**
     * @return the nn513
     */
    public int getNn513() {
        return nn513;
    }

    /**
     * @param nn513 the nn513 to set
     */
    public void setNn513(int nn513) {
        this.nn513 = nn513;
    }

    /**
     * @return the fn500
     */
    public int getFn500() {
        return fn500;
    }

    /**
     * @param fn500 the fn500 to set
     */
    public void setFn500(int fn500) {
        this.fn500 = fn500;
    }

    /**
     * @return the pn500
     */
    public int getPn500() {
        return pn500;
    }

    /**
     * @param pn500 the pn500 to set
     */
    public void setPn500(int pn500) {
        this.pn500 = pn500;
    }

    
}
